package com.acme.domain.bank;

import com.acme.exceptions.ClientExistsException;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

public class Bank implements Serializable {
    private final List<Client> clients = new LinkedList<>();

    public Client addClient(final Client client) throws ClientExistsException {
        for (Client existedClient : clients) {
            if (client.getName().equals(existedClient.getName())) {
                throw new ClientExistsException(String.format("Client %s already exists.", client), client);
            }
        }
        clients.add(client);
        return client;
    }

    @Override
    public String toString() {
        return "Bank{" +
                "clients=" + clients +
                '}';
    }
}